// 获取 sts 信息
function getSTS() {
  return uni.$u.http.get("pc/sts/get");
}

// 上传文件
export async function uploadFile(data) {
  let stsInfo = await getSTS();
  let key = `${stsInfo.data.dir}/${String(new Date().getTime())}_${
    // data.file.name
    data.filePath
  }`;
  let formData = {
    success_action_status: "200",
    policy: stsInfo.data.policy,
    "x-oss-signature": stsInfo.data.signature,
    "x-oss-signature-version": "OSS4-HMAC-SHA256",
    "x-oss-credential": stsInfo.data.x_oss_credential,
    "x-oss-date": stsInfo.data.x_oss_date,
    key: key,
    "x-oss-security-token": stsInfo.data.security_token,
    // file: data.file,
  };
  await uni.$u.http.upload(stsInfo.data.host, {
    filePath: data.filePath,
    formData,
    name: "file",
    baseURL: "",
  });
  return {
    data: { url: `${stsInfo.data.host}/${key}` },
    code: 20000,
  };
}
